{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from collections import deque\n",
    "\n",
    "# 初始化双端队列\n",
    "lst = deque([1, 2, 3, 4, 5])\n",
    "\n",
    "# 检查是否为空，输出：False\n",
    "print(len(lst) == 0)\n",
    "\n",
    "# 获取大小，输出：5\n",
    "print(len(lst))\n",
    "\n",
    "# 在头部插入 0，尾部插入 6\n",
    "lst.appendleft(0)\n",
    "lst.append(6)\n",
    "\n",
    "# 获取头部和尾部元素，输出：0 6\n",
    "print(lst[0], lst[-1])\n",
    "\n",
    "# 删除头部和尾部元素\n",
    "lst.popleft()\n",
    "lst.pop()\n",
    "\n",
    "# 在索引 2 处插入 99\n",
    "lst.insert(2, 99)\n",
    "\n",
    "# 删除索引 1 处的元素\n",
    "del lst[1]\n",
    "\n",
    "# 遍历双端队列\n",
    "# 输出：1 99 3 4 5\n",
    "for val in lst:\n",
    "    print(val, end=\" \")\n",
    "print()"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
